package com.movie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.movie.bean.PlayRoom;
import com.movie.bean.vo.PageParams;
import com.movie.mapper.PlayRoomMapper;
import com.movie.service.PlayRoomService;
import com.movie.utils.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Liu Jiaquan
 * @Description
 * @date 2024/8/5 12:29
 */
@Service
public class PlayRoomServiceImpl implements PlayRoomService {

    @Autowired
    private PlayRoomMapper playRoomMapper;
    @Override
    public void save(PlayRoom playRoom) {
        BeanUtil.setDefault(playRoom);
        if (BeanUtil.isNew(playRoom)){
            playRoomMapper.insert(playRoom);
        }else {
            playRoomMapper.updateById(playRoom);
        }
    }

    @Override
    public Page<PlayRoom> page(PageParams pageParams) {
        return playRoomMapper.selectPage(Page.of(pageParams.getPageNo(),pageParams.getPageSize()),new QueryWrapper<PlayRoom>().ne("status",9));
    }

    @Override
    public List<PlayRoom> roomList() {
        return playRoomMapper.selectList(new QueryWrapper<>());
    }

    @Override
    public int updateStatus(PlayRoom playRoom) {
        PlayRoom room = new PlayRoom();
        room.setStatus(playRoom.getStatus());
        room.setId(playRoom.getId());
        return playRoomMapper.updateById(room);
    }
}
